package cn.demo.configServer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: liujiahao
 * @Description:
 */
@SpringBootApplication
@EnableResourceServer
@RestController
@EnableAuthorizationServer
@Slf4j
public class OauthApplication {
    @RequestMapping(value = {"/user"},produces = "application/json")
    public Map<String,Object> user(OAuth2Authentication user){
        log.info("进入验证");
        Map<String,Object> userInfo=new HashMap<String, Object>();
        userInfo.put("user",user.getUserAuthentication().getPrincipal());
        userInfo.put("authorities",user.getUserAuthentication().getAuthorities());
        return userInfo;
    }
    public static void main(String[] args) {
        SpringApplication.run(OauthApplication.class, args);
    }

}
